package com.drinks.yiniang.io.api;

import com.alibaba.fastjson.JSON;
import com.drinks.yiniang.common.help.PayManager;
import com.drinks.yiniang.entity.common.StringJson;
import com.drinks.yiniang.entity.common.StringMsgJson;
import com.drinks.yiniang.entity.goods.RefundGoodsJson;
import com.drinks.yiniang.entity.pay.AliPayJson;
import com.drinks.yiniang.entity.pay.WeiXinPayJson;
import com.drinks.yiniang.entity.shop.ShopJson;
import com.drinks.yiniang.entity.user.order.MyOrderJson;
import com.drinks.yiniang.entity.user.order.OrderConfirmJson;
import com.drinks.yiniang.entity.user.order.OrderCouponJson;
import com.drinks.yiniang.entity.user.order.OrderDetailJson;
import com.drinks.yiniang.entity.user.order.OrderEvaluateJson;
import com.drinks.yiniang.entity.user.order.OrderSubmitJson;
import com.drinks.yiniang.io.http.HttpUrls;
import com.hansen.library.Constants;
import com.hansen.library.entity.BaseJson;
import com.hansen.library.io.tuple.Tuple2;
import com.hansen.library.listener.APIRequestCallback;
import com.hansen.library.utils.LogUtils;
import com.hansen.library.utils.StringUtils;

/**
 * 订单相关api
 * Created by han on 2019/3/6 0006.
 */

public class OrderApiIO extends BaseApiIO {
    volatile static OrderApiIO instance;

    static public OrderApiIO getInstance() {
        if (instance == null) {
            synchronized (OrderApiIO.class) {
                if (instance == null) {
                    instance = new OrderApiIO();
                }
            }
        }
        return instance;
    }

    /**
     * 订单列表
     *
     * @param status   -1全部 0待支付 1已支付 2已发货(待收货) 3已送达 4交易完成（待评价） 5已评价
     * @param page     页码
     * @param callback
     */
    public void getOrderList(String status, int page, final APIRequestCallback<MyOrderJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("status", status);
        paramsMap.put("page", String.valueOf(page));
        paramsMap.put("per_page", Constants.PAGE_SIZE);

        MainApiIO.getInstance().postRequest(HttpUrls.API_ORDER_LIST, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("订单列表===onSuccess");

                MyOrderJson mDataJson = JSON.parseObject(res, MyOrderJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null && mDataJson.getData().getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 订单详情
     *
     * @param orderId     订单id
     * @param orderStatus 类型 0待支付的订单详情（查询的是总的订单） 1其他状态订单详情
     * @param callback
     */
    public void getOrderDetail(String orderId, String orderStatus, final APIRequestCallback<OrderDetailJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("order_id", orderId);
        paramsMap.put("type", orderStatus);

        MainApiIO.getInstance().postRequest(HttpUrls.API_ORDER_DETAIL, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("订单详情===onSuccess");

                OrderDetailJson mDataJson = JSON.parseObject(res, OrderDetailJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null && mDataJson.getData().getGoods() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 订单取消
     *
     * @param orderId  订单id
     * @param callback
     */
    public void doOrderCancel(String orderId, final APIRequestCallback<BaseJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("order_id", orderId);

        MainApiIO.getInstance().postRequest(HttpUrls.API_ORDER_CANCEL, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("订单取消===onSuccess");

                BaseJson mDataJson = JSON.parseObject(res, BaseJson.class);

                if (callback != null) {
                    if (mDataJson != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 订单删除
     *
     * @param orderId  订单id
     * @param callback
     */
    public void doOrderDelete(String orderId, final APIRequestCallback<StringJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("order_id", orderId);

        MainApiIO.getInstance().postRequest(HttpUrls.API_ORDER_DELETE, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("订单删除===onSuccess");

                StringJson mDataJson = JSON.parseObject(res, StringJson.class);

                if (callback != null) {
                    if (mDataJson != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 订单确认收货
     *
     * @param orderId  订单id
     * @param callback
     */
    public void doOrderConfirm(String orderId, final APIRequestCallback<BaseJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("order_id", orderId);

        MainApiIO.getInstance().postRequest(HttpUrls.API_ORDER_RECEIPT_CONFIRM, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("订单确认收货===onSuccess");

                BaseJson mDataJson = JSON.parseObject(res, BaseJson.class);

                if (callback != null) {
                    if (mDataJson != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 订单提醒收货
     *
     * @param orderId  订单id
     * @param callback
     */
    public void doOrderRemindDeliver(String orderId, final APIRequestCallback<StringMsgJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("order_id", orderId);

        MainApiIO.getInstance().postRequest(HttpUrls.API_ORDER_REMIND_DELIVER, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("订单提醒收货===onSuccess");

                StringMsgJson mDataJson = JSON.parseObject(res, StringMsgJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 获取退款的商品
     *
     * @param orderNo  订单号
     * @param goodsId  商品id
     * @param callback
     */
    public void getRefundGoodsList(String orderNo, String goodsId, final APIRequestCallback<RefundGoodsJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("order_no", orderNo);
        paramsMap.put("goods_id", goodsId);

        MainApiIO.getInstance().postRequest(HttpUrls.API_GET_REFUND_GOODS_LIST, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("获取退款的商品===onSuccess");

                RefundGoodsJson mDataJson = JSON.parseObject(res, RefundGoodsJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null && mDataJson.getData().getGoods_list() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 商品提交申请退款
     *
     * @param orderNo     订单号
     * @param goodsId     商品id (多个逗号分隔 1,2)
     * @param reasonId    原因id
     * @param refundMoney 金额
     * @param imgId       图片id (多个逗号分隔 1,2)
     * @param callback
     */
    public void submitRefundGoods(String orderNo, String goodsId, String reasonId, String refundMoney,
                                  String imgId, final APIRequestCallback<BaseJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("order_no", orderNo);
        paramsMap.put("goods_id", goodsId);
        paramsMap.put("refund_reason_id", reasonId);
        paramsMap.put("refund_amount", refundMoney);
        paramsMap.put("images_ids", imgId);

        MainApiIO.getInstance().postRequest(HttpUrls.API_REFUND_GOODS_APPLY, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("商品提交申请退款===onSuccess");

                BaseJson mDataJson = JSON.parseObject(res, BaseJson.class);

                if (callback != null) {
                    if (mDataJson != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 确认订单商品信息
     *
     * @param goodsId  商品id
     * @param skuId    sku id
     * @param num      商品数量
     * @param callback
     */
    public void getOrderConfirmGoods(String goodsId, String skuId, int num, final APIRequestCallback<OrderConfirmJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("goods_id", goodsId);
        paramsMap.put("goods_sku_id", skuId);
        paramsMap.put("num", String.valueOf(num));

        MainApiIO.getInstance().postRequest(HttpUrls.API_ORDER_CONFIRM_GOODS, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("确认订单商品信息===onSuccess");

                OrderConfirmJson mDataJson = JSON.parseObject(res, OrderConfirmJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 确认购物车订单商品信息
     *
     * @param cartId   购物车id(多个逗号分隔)
     * @param callback
     */
    public void getOrderConfirmCartGoods(String cartId, final APIRequestCallback<OrderConfirmJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("cart_ids", cartId);

        MainApiIO.getInstance().postRequest(HttpUrls.API_ORDER_CONFIRM_CART_GOODS, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("确认购物车订单商品信息===onSuccess");

                OrderConfirmJson mDataJson = JSON.parseObject(res, OrderConfirmJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null && mDataJson.getData().getGoods_list() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 获取订单可使用的优惠券
     *
     * @param storeId  门店id, 传值获取的包含门店优惠券, 不传值返回通用的优惠券
     * @param orderPrice 订单价格
     * @param callback
     */
    public void getOrderCoupon(String storeId, String orderPrice, final APIRequestCallback<OrderCouponJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("stores_id", storeId);
        paramsMap.put("order_price", orderPrice);

        MainApiIO.getInstance().postRequest(HttpUrls.API_ORDER_CAN_USE_COUPON, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("获取订单可使用的优惠券===onSuccess");

                OrderCouponJson mDataJson = JSON.parseObject(res, OrderCouponJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 提交单个商品订单
     *
     * @param goodsId   商品id
     * @param skuId     sku id
     * @param num       数量
     * @param lngLat    经纬度(,分割)
     * @param addressId 地址id
     * @param selfGet   是否自提 1-是 （扫描商品时，有提示）
     * @param storesId  自提选择的门店id
     * @param couponId  优惠券id
     * @param mark      备注
     * @param callback
     */
    public void submitOrderOneGoods(String goodsId, String skuId, int num, String lngLat, String addressId, String selfGet,
                                    String storesId, String couponId, String mark,
                                    final APIRequestCallback<OrderSubmitJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("goods_id", goodsId);
        paramsMap.put("goods_sku_id", skuId);
        paramsMap.put("num", String.valueOf(num));
        paramsMap.put("lng_lat", lngLat);
        paramsMap.put("address_id", addressId);
        paramsMap.put("self_get", selfGet);
        paramsMap.put("stores_id", storesId);
        paramsMap.put("coupons_id", couponId);
        paramsMap.put("mark", mark);

        MainApiIO.getInstance().postRequest(HttpUrls.API_SUBMIT_ORDER_ONE_GOODS, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("提交单个商品订单===onSuccess");

                OrderSubmitJson mDataJson = JSON.parseObject(res, OrderSubmitJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 提交单个商品订单
     *
     * @param cartId    购物车id
     * @param lngLat    经纬度
     * @param addressId 地址id
     * @param selfGet   是否自提 1-是 （扫描商品时，有提示）
     * @param storesId  自提选择的门店id
     * @param couponId  优惠券id
     * @param mark      备注
     * @param callback
     */
    public void submitOrderMoreGoods(String cartId, String lngLat, String addressId, String selfGet,
                                     String storesId, String couponId, String mark, final APIRequestCallback<OrderSubmitJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("cart_ids", cartId);
        paramsMap.put("lng_lat", lngLat);
        paramsMap.put("address_id", addressId);
        paramsMap.put("self_get", selfGet);
        paramsMap.put("stores_id", storesId);
        paramsMap.put("coupons_id", couponId);
        paramsMap.put("mark", mark);

        MainApiIO.getInstance().postRequest(HttpUrls.API_SUBMIT_ORDER_MORE_GOODS, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("提交单个商品订单===onSuccess");

                OrderSubmitJson mDataJson = JSON.parseObject(res, OrderSubmitJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 钱包支付
     *
     * @param orderNum 订单号
     * @param callback
     */
    public void doPayByWallet(String orderNum, final APIRequestCallback<AliPayJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("pay_order_no", orderNum);
        paramsMap.put("pay_type", String.valueOf(PayManager.PAY_CHANNEL_WALLET));

        MainApiIO.getInstance().postRequest(HttpUrls.API_ORDER_PAY, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("钱包支付===onSuccess");

                AliPayJson mDataJson = JSON.parseObject(res, AliPayJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 支付宝支付
     *
     * @param orderNum 订单号
     * @param callback
     */
    public void doPayByAliPay(String orderNum, final APIRequestCallback<AliPayJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("pay_order_no", orderNum);
        paramsMap.put("pay_type", String.valueOf(PayManager.PAY_CHANNEL_ALIPAY));

        MainApiIO.getInstance().postRequest(HttpUrls.API_ORDER_PAY, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("支付宝支付===onSuccess");

                AliPayJson mDataJson = JSON.parseObject(res, AliPayJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 微信支付
     *
     * @param orderNum 订单号
     * @param callback
     */
    public void doPayByWeiXin(String orderNum, final APIRequestCallback<WeiXinPayJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("pay_order_no", orderNum);
        paramsMap.put("pay_type", String.valueOf(PayManager.PAY_CHANNEL_WX));

        MainApiIO.getInstance().postRequest(HttpUrls.API_ORDER_PAY, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("微信支付===onSuccess");

                WeiXinPayJson mDataJson = JSON.parseObject(res, WeiXinPayJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 获取订单待评价的商品
     *
     * @param orderId  订单id
     * @param callback
     */
    public void getOrderCommentsGoodsList(String orderId, final APIRequestCallback<OrderEvaluateJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("order_id", orderId);

        MainApiIO.getInstance().postRequest(HttpUrls.API_GET_ORDER_COMMENTS_LIST, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("获取订单待评价的商品===onSuccess");

                OrderEvaluateJson mDataJson = JSON.parseObject(res, OrderEvaluateJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null && mDataJson.getData().getGoods() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 查询订单支付结果
     *
     * @param orderNo  订单号
     * @param type     支付类型
     * @param callback
     */
    public void getOrderPayResult(String orderNo, int type, final APIRequestCallback<OrderEvaluateJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("pay_order_no", orderNo);
        paramsMap.put("pay_type", String.valueOf(type));

        MainApiIO.getInstance().postRequest(HttpUrls.API_ORDER_PAY_QUERY, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("查询订单支付结果===onSuccess");

                OrderEvaluateJson mDataJson = JSON.parseObject(res, OrderEvaluateJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null && mDataJson.getData().getGoods() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 提交订单评价
     *
     * @param orderId   订单id
     * @param goodsJson 商品列表json [{"goods_id":1,"content":"dd","score":5,"images_ids":"17,18","radar":"4,2,3,5,4,1"}]
     * @param callback
     */
    public void submnitOrderComments(String orderId, String goodsJson, final APIRequestCallback<StringJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("order_id", orderId);
        paramsMap.put("goods", goodsJson);

        MainApiIO.getInstance().postRequest(HttpUrls.API_SUBMIT_ORDER_COMMENTS, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("提交订单评价===onSuccess");

                StringJson mDataJson = JSON.parseObject(res, StringJson.class);

                if (callback != null) {
                    if (mDataJson != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }
}
